/* Copyright 2009 Anthony Surma
This file is part of Java's Kademlia Extension (JKADX).

JKADX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

JKADX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JKADX.  If not, see <http://www.gnu.org/licenses/>.
 */

package jkadx.xml;

import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;

public class ElementNode
{
    final    String name;
    volatile String data;



    
    public ElementNode(String name, String data)
    {
        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
        this.name = name;
        this.data = data;

    }
    
    @Override
    public String toString()
    {
        return name + " = " + data;
    }

    public String getName()
    {
        return name;
    }
    
    public void setData(String data)
    {
        this.data = data;
    }
    
    public String getData()
    {
        return data;
    }
    
    public static String getDataFor(String name, ArrayList<ElementNode> arraylist)
    {
        String data = null;

        for (ElementNode node : arraylist)
        {
            if (node.getName().equals(name))
            {
                data = node.getData();
                break;
            }
        }            
        return data;
    }

    public static String setDataFor(String name, String data, ArrayList<ElementNode> arraylist)
    {
        for (ElementNode node : arraylist)
        {
            if (node.getName().equals(name))
            {
                node.setData(data);
                break;
            }
        }            
        return data;
    }    
}
